package com.potenza.training.resume.controller;

import com.alibaba.fastjson.JSON;
import com.potenza.training.resume.config.IKAnalyzerUtil;
import com.potenza.training.resume.entity.Cs;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

@RestController
@RequestMapping("/resume/ikddd")
public class AnalyzerController {
    /**
     * http://localhost:8081/IkAnalyzer?word=老板请给我一把油纸伞
     *
     * @param word
     * @return
     */
    @RequestMapping("/IkAnalyzer")
    public String IkAnalyzer(String word) throws IOException {
        StringBuffer sb = new StringBuffer();
        String aa="[{\"id\":1,\"text\":\"联想\"},{\"id\":3,\"text\":\"三星\"},{\"id\":2,\"text\":\"华为\"},{\"id\":5,\"text\":\"OPPO\"},{\"id\":4,\"text\":\"小米\"},{\"id\":9,\"text\":\"苹果\"},{\"id\":8,\"text\":\"魅族\"},{\"id\":6,\"text\":\"360\"},{\"id\":10,\"text\":\"VIVO\"},{\"id\":11,\"text\":\"诺基亚\"},{\"id\":12,\"text\":\"锤子\"}]";
        List<Cs> cs = JSON.parseArray(aa, Cs.class);
        int size = cs.size();
        int count=0;
        List<String> list11 =  IKAnalyzerUtil.cut(word);
        Set<String> list = new HashSet<>(list11);
        System.out.println(size+"--------------------------");
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()){
            String next = iterator.next();
            for (Cs c : cs) {
                if(next.equals(c.getText())){
                    count++;
                }
            }
        }
        int cc=(int)((double)size*0.8);
       if(count>=cc){
           return "正确";
       }else {
           return "错误";
       }
    }
}